<template>
  <div id="Address">
    <van-nav-bar
      title="地址列表"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />

    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      :disabled-list="disabledList"
      disabled-text="以下地址超出配送范围"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />

    <van-overlay :show="show" @click="show = false">
      <div class="wrapper" @click.stop>
        <div class="block" />
      </div>
    </van-overlay>
  </div>
</template>

<script>
import { getList } from "@/api";
import { loading, clearToast } from "@/utils/loading";
export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],
      disabledList: [],
    };
  },
  methods: {
    onClickLeft() {
      Toast("返回");
    },
    onClickRight() {
      Toast("按钮");
    },
    onAdd() {
      Toast("新增地址");
    },
    onEdit(item, index) {
      Toast("编辑地址:" + index);
    },
    formatList(list) {
      return list.map((item) => ({
        ...item,
      }));
    },
  },

  mounted() {
    loading();
    getList().then((res) => {
      this.list = this.formatList(res.data);
      console.log(this.list);
      clearToast();
    });
  },
};
</script>

<style>
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.block {
  width: 120px;
  height: 120px;
  background-color: #fff;
}
</style>
